<?php

require_once(WSB_XTENSION_PATH . 'news/models/DbTable/News/Table.php');

class News_DetailController extends WSB_Xtension_Extension
{

	/**
	 * @return string
	 */
	public function renderForBackend()
	{
		return get_class($this);
	}

	public function init()
	{
		$config = $this->getConfiguration();
		$this->assignToView('detailPageId', empty($config->detailPageId) ? $this->getPageId() : $config->detailPageId);
		$this->assignToView('listPageId', empty($config->listPageId) ? $this->getPageId() : $config->listPageId);
	}

	/**
	 * @see: News_IndexController::detailAction()
	 */
	public function indexAction()
	{
		$id = intval($this->getParam('id'));
		if($id > 0) {
			$table = new News_Model_DbTable_News_Table();
			$select = $table->select();
			$select->where('id=?', $id);
			$model = $table->fetchRow($select);
			if($model instanceof News_Model_DbTable_News_Row) {
				$this->_view->model = $model;
				$this->renderView('detail.phtml');
			} else {
				$this->addPageNotFoundHeader();
				$this->renderView('detail_error.phtml');
			}
		} else {
			$this->addPageNotFoundHeader();
			$this->renderView('detail_error.phtml');
		}
	}

}
